package com.qf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

/**
 * 环绕通知
 */
public class MyAdvice3 implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        //目标方法执行之前的逻辑，在这里写
        long start = System.currentTimeMillis();
        //如何让原来的目标方法能够继续执行
        Object result = methodInvocation.proceed();

        //目标方法执行之后的逻辑，在这里写
        long end = System.currentTimeMillis();
        System.out.println("方法执行消耗了"+(end-start)+"ms");
        return result;
    }
}
